package com.example.rent.controller.yx;

import com.example.rent.Result;
import com.example.rent.entity.Houseowner;
import com.example.rent.mapper.yx.HouseownerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginHouseOwnerController {
    @Autowired
    private HouseownerMapper houseownerMapper;

    @PostMapping("/loginHouseOwner")
    public Result  loginHouseOwner(@RequestParam("hphone")String hphone,
                                   @RequestParam("password") String password){
        long id = Long.parseLong(hphone);
        Houseowner houseowner = houseownerMapper.selectById(id);
        if (houseowner == null) {
            return Result.fail();
        } else if(houseowner.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))){
            return Result.success(houseowner);
        } else {
            return Result.fail();
        }
    }
}
